       IDENTIFICATION DIVISION.
       PROGRAM-ID.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 STDREC.
        02 STD OCCURS 11 TIMES.
          03 NAME    PIC X(20).
          03 ROLL    PIC 9(5).
          03 TOTAL   PIC 9(4).
	  03 MARK    PIC 9(3) OCCURS 3 TIMES.
       77 N    PIC 99.
       77 I    PIC 99.   
       77 J    PIC 99. 
       77 TEMP PIC ZZZZ.
       77 C    PIC X.

       PROCEDURE DIVISION.
       MAINPARA.
           PERFORM GETDATA.
           PERFORM SORTDATA.
           PERFORM DISPDATA.
           STOP RUN.
       
       GETDATA.
           DISPLAY "---DATA ENTRY---".
           DISPLAY (LIN, COL) "NO. OF STUDENTS: ".
           ACCEPT N.
           MOVE 0 TO I.
           PERFORM ENTRY N TIMES.
	   ACCEPT C.
       ENTRY.
           ADD 1 TO I.
           DISPLAY (LIN, COL) "NAME:", I ": ".
           ACCEPT NAME OF STD(I).
           MOVE 0 TO TOTAL(I).
	   PERFORM INDSUB VARYING J FROM 1 BY 1 UNTIL J > 3.
	   DISPLAY " ".
       INDSUB.
           DISPLAY (LIN, COL) "MARKS ", J ": ".
           ACCEPT MARK(I, J).
           ADD MARK(I, J) TO TOTAL(I).
       
       SORTDATA.
           PERFORM SORTER N TIMES.
       
       SORTER.
           MOVE 1 TO I.
           PERFORM COMPARE UNTIL I = N.
       COMPARE.    
           IF TOTAL(I) > TOTAL(I + 1) 
              MOVE STD(I) TO STD(11),
              MOVE STD(I + 1) TO STD(I),
              MOVE STD(11) TO STD(I + 1).
           ADD 1 TO I.
           
       DISPDATA.
	   DISPLAY (1, 1) ERASE.
           DISPLAY "-------- SORTED LIST --------".
           PERFORM SHOW VARYING I FROM 1 BY 1 UNTIL I > N. 
           DISPLAY "-----------------------------".
	   DISPLAY " ".
	   ACCEPT C.
       SHOW.
           MOVE TOTAL OF STD(I) TO TEMP.
           DISPLAY NAME OF STD(I), "  ", TEMP.





